<?php

namespace App\Console\Commands;

use App\Http\Controllers\GiftBagController;
use App\Http\Controllers\LoverController;
use App\Http\Model\Config;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Redis;

class LoverActivity extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'lover:loverActivity {all=0}';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '七夕活动';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
        $this->configModel = new Config();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {

        $all = (int)$this->argument('all');

        if (0 === $all) {
            //查看靓号
            $this->getCache();
        } elseif (1 === $all) {
            //删除靓号
            $this->delCache();
        } elseif (3 === $all) {
            //入redis
            $this->liangNumCache();
        } elseif (4 === $all) {
            //喜鹊彩蛋达标
            $this->fowlCpEgg();
        }

    }


    private function liangNumCache()
    {
        $liang_cache = Redis::lrange('lover_liang', 0, -1);
        if (empty($liang_cache)) {
            $config = $this->configModel->getShareGoodsConfig(4);
            $liang_num = explode(',', $config['lover_liang_num']['value']);
            for ($i = 0; $i < 6; $i++) {
                Redis::lpush('lover_liang', $liang_num[$i]);
            }
        }
    }

    private function fowlCpEgg()
    {
        $cp_egg = new LoverController();
        echo $cp_egg->cpEgg();
    }

    private function getCache()
    {
        $liang_cache = Redis::lrange('lover_liang', 0, -1);
        dump($liang_cache);
    }

    private function delCache()
    {
        $liang_cache = Redis::lrange('lover_liang', 0, -1);
        for($i=0;$i<count($liang_cache);$i++){
            Redis::lpop('lover_liang');
        }
    }


}
